<template>
  <!-- 用户地址管理 -->
  <div class="address">
    <!-- 顶部返回栏 -->
    <van-nav-bar
      title="标题"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-address-edit
      ref="ipt"
      :area-list="areaList"
      show-postal
      show-delete
      show-set-default
      show-search-result
      save-button-text="更新"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      :address-info="{
        name: info.name,
        tel: info.tel,
        addressDetail: info.address,
        areaCode: info.areaCode,
        postalCode: info.areaCode,
        isDefault: info.isDefault,
      }"
      @save="onSave"
      @delete="onDelete"
    />
  </div>
</template>

<script>
import { Toast } from "vant";
import { areaList } from "@vant/area-data";
import { mapState, mapMutations } from "vuex";
export default {
  data() {
    return {
      // 选择省市区(县)列表
      areaList,
    };
  },
  created() {},
  computed: {
        ...mapState("address", ["list","info","findId"]),
  },
  mounted() {
    let resultProvince = Object.entries(this.areaList.province_list);
    let resultCity = Object.entries(this.areaList.city_list);
    let resultArea = Object.entries(this.areaList.county_list);
    console.log(resultProvince);
    console.log(resultCity);
    console.log(resultArea);
    let arr = resultArea.filter((item) => {
      return item[1] == "嵩县";
      
    });
    console.log(arr);
  },
  methods: {
    // 更新操作
    onSave(val) {
      this.updata(val);
      this.$router.push({
         name:"conAddress"
      })
      Toast("save");
    },
    ...mapMutations("address", {
      add: "add",
      updata:"updata",
      delData:"delData"
    }),

    onDelete() {
      this.delData();
      this.$router.push({
         name:"conAddress",
      })
       Toast("删除地址成功");
    },

    onClickLeft() {
      this.$router.go(-1);
    },
  },
};
</script>

<style></style>
